// base
import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
// less
import './index.less'
import If from '../../../components/page-components/if'
import scaleImageSrc from '../../../util/pagemethods/scaleImageSrc'
import { judgeLoginStatus } from '../../../util/login_status'
import tool from '../../../util/tool'

class ListItem extends Component {
  componentWillMount() {
    // onLoad
  }

  componentDidMount() {
    // onready
  }

  componentWillUnmount() {
    // onUnload
  }

  componentWillReceiveProps(nextprops) {}

  jumpTo = tool.throttle(() => {
    const { input, url, num, onJumpTo, name } = this.props
    if(onJumpTo) {
      onJumpTo(name)
    } else {
      if (input) {
        // 跳转自我评价
        this.props.onTap()
      } else if (!num && url === 'new-work-exp') {
        // 创建工作经验
        judgeLoginStatus({ url: 'work-exp' })
      } else if (!num && url === 'new-educationa-information') {
        // 创建教育信息
        judgeLoginStatus({ url: 'education-information' })
      } else {
        // 跳转正常页面
        judgeLoginStatus({ url })
      }
    }
  })

  render() {
    let { icon, name, desc, type, image, num } = this.props
    return (
      <View className="ListItem_id33630" onClick={this.jumpTo}>
        <View className="item">
          <Image className="icon" src={icon} />
          <View className="name">{name}</View>
        </View>
        <View className="item">
          <If visible={!type}>
            <View className="num">{num || ''}</View>
            <View className="desc">{desc}</View>
          </If>
          <If visible={type == 'image'}>
            <If
              visible={image && image.length > 0}
              renderElse={<View className="desc">{desc}</View>}
            >
              <View className="image">
                {image &&
                  image.map((item, index) => {
                    return index < 2 ? (
                      <Image
                        class="image-item"
                        src={scaleImageSrc(item.pic, 72)}
                        mode="aspectFill"
                      />
                    ) : null
                  })}
                {image.length < 2 ? '' : <View className="image-count">{`+${image.length}`}</View>}
              </View>
            </If>
          </If>
          <Image
            className="arrow"
            src="https://imagesize.hrwork.com/sp/files/3a51bf62-401e-4c28-9f8e-e7f922dad287.png"
          />
        </View>
      </View>
    )
  }
}

export default ListItem
